<template>
  <div class="none">
    <nav-header></nav-header>
    <div class="nav">
      <ul>
        <li class="li1" @click="refreshFood()"><img src="@/assets/pic/food.png" alt=""><span>food</span></li>
        <li class="li1" @click="refreshSport()"><img src="@/assets/pic/yundong.png" alt=""><span>sport</span></li>
        <li class="li1" @click="refreshWork()"><img src="@/assets/pic/bangong0.png" alt=""><span>work</span></li>
        <li class="li1 li2"><img src="@/assets/pic/down.png" alt=""><span>more</span></li>
      </ul>
    </div>
    <div class="goods" v-for="item in goodList" :key="item.value">
      <ul>
        <li>
          <div class="pic">
            <a href="javascript:;">
              <img v-bind:src="'/static/'+item.pictureUrl" alt>
            </a>
          </div>
          <div class="main">
            <div class="name">{{item.productName}}</div>
            <div class="else">
              <p class="goods-sales-price">$ <em>{{item.productprice}}</em></p>
            </div>
          </div>
        </li>
      </ul>
    </div>
    <div class="goods" v-for="item in goodsList" :key="item.value" @click="productDetail(item)">
      <!-- <router-link v-bain:to="{path:'/details',params:{productId:item.id}}"> -->
      <ul>
        <li>
          <div class="pic">
            <a href="javascript:;">
              <img v-bind:src="item.pictureUrl" alt>
            </a>
          </div>
          <div class="main">
            <div class="name">{{item.productName}}</div>
            <div class="else">
              <span>price:{{item.productPrice}}</span>
            </div>
          </div>
        </li>
      </ul>
      <!-- </router-link> -->
    </div>
    <h3>欢迎 {{text}}</h3>
  </div>
</template>
<style scoped>
.none {
  background-color: #f4f4f4;
  /* margin-right: 0px; */
}
.none::after{
  clear: both;
  content:'';
  height: 0;
  display: block;
  visibility: hidden;
}
h3{
  color: #f4f4f4;
}
.nav{
    margin: 0;
    width:100%;
    height: 50px;
    background-color: #fff;
}
ul,li{ padding:0;margin:0;list-style:none}
.li1{
    width: 26%;
    height: 45px;
    float: left;
    margin-right: 2%;
    margin-top: 5px;
    /* background-color: #cfc; */
}
.li1 img{
    width: 20px;
    height: 20px;
    margin: 2.5px 2px;
}
.li1 span{
    display: block;
    font-size: 14px;
    line-height: 14px;
    text-align: center;
}
.li2{
    width: 10%;
    height: 45px;
    float: left;
    margin-left: 3%;
    margin-top: 5px;
    /* background-color: #cfc; */
}
.goods {
  width: 48%;
  height: 250px;
  float: left;
  margin: 1% 1%;
  position: relative;
  /* background-color: #fcf; */
}
.pic {
  width: 100%;
  height: 180px;
}
img {
  width: 100%;
  height: 100%;
}
.main {
  width: 100%;
  height: 70px;
}
.name {
  width: 100%;
  height: 60%;
  text-align: left;
  overflow: hidden;
  background-color: #fff;
  font-size: 18px;
  line-height: 22px;
}
.else {
  width: 100%;
  height: 40%;
  background-color: #fff;
  color: red;
  font-size: 22px;
}
.goods-sales-price{
    background-color: #fff;
    font-size: 20px;
    line-height: 22px;
    margin: 0;
    font-weight: bold;
    position: absolute;
    color: #e4393c;
}
em{
    font-size: 26px;
    font-style: normal;
}
</style>

<script>
import NavHeader from "@/components/NavHeader.vue";
import axios from "axios";
export default {
  data() {
    return {
      name: "niuchanxiao",
      goodsList: [],
      goodList: [],
      text: {}
    };
  },
  components: {
    NavHeader
  },
  mounted: function() {
    this.getGoodList();
    this.getGoodsList();
  },
  methods: {
    getGoodList() {
      axios.get("/api/appData").then(result => {
        var res = result.data;
        console.log(res);
        this.goodList = res.data.result;
      });
    },
    getGoodsList() {
      axios
        .get(
          "http://106.13.96.243:8080/Neuq_JavaWeb_war_exploded//ProductController/getAllProducts"
        )
        .then(result => {
          var res = result.data.data;
          console.log(res);
          this.goodsList = res;
        });
    },
    refreshFood(){
      var type="食品";
      console.log(type);
      axios.get("http://106.13.96.243:8080/Neuq_JavaWeb_war_exploded/ProductController/handleGetProductsByProductType",{params:{productType:type}}).then(result => {
        var res = result.data.data;
        console.log(res);
        this.goodsList = res;
      });
    },
    refreshSport(){
      var type="运动器材";
      console.log(type);
      axios.get("http://106.13.96.243:8080/Neuq_JavaWeb_war_exploded/ProductController/handleGetProductsByProductType",{params:{productType:type}}).then(result => {
        var res = result.data.data;
        console.log(res);
        this.goodsList = res;
      });
    },
    refreshWork(){
      var type="办公用品";
      console.log(type);
      axios.get("http://106.13.96.243:8080/Neuq_JavaWeb_war_exploded/ProductController/handleGetProductsByProductType",{params:{productType:type}}).then(result => {
        var res = result.data.data;
        console.log(res);
        this.goodsList = res;
      });
    },
    productDetail(item) {
      // console.log(`${item.productId}`);
      this.$router.push({ 
        path: '/details' ,
        query: {
          Id: `${item.productId}`
        }
      });
    }
  }
};
</script>